import type { AppBuilderOptions } from '@vben/vite-config';

import path from 'node:path';

import { defineConfig } from '@vben/vite-config';

import ElementPlus from 'unplugin-element-plus/vite';
import yaml from 'yamljs';

const cfg: AppBuilderOptions = yaml.load(path.resolve('builder.yml'));
export default defineConfig(async () => {
  return {
    application: {
      appPlugin: true,
      appPluginOptions: cfg,
    },
    vite: {
      plugins: [
        ElementPlus({
          format: 'esm',
        }),
      ],
      server: {
        proxy: {
          '/api': {
            changeOrigin: true,
            rewrite: (path: string) => path.replace(/^\/api/, ''),
            // mock代理目标地址
            target: 'http://124.223.104.228:18443/',
            ws: true,
          },
        },
      },
    },
  };
});
